﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FerrScript.Builder
{
    class RandomCondBlock : BuilderBlock
    {
        #region Fields
        float min, max;
        float threshold;
        #endregion

        #region Properties
        public float Min
        {
            get { return min; }
            set { min = value; }
        }
        public float Max
        {
            get { return max; }
            set { max = value; }
        }
        public float Threshold
        {
            get { return threshold; }
            set { threshold = value; }
        }
        #endregion

        #region Constructors
        public RandomCondBlock() 
            : this(0.5f) { }
        public RandomCondBlock(float aThreshold)
            : this(aThreshold, 0, 1) { }
        public RandomCondBlock(float aThreshold, float aMax)
            : this(aThreshold, 0, aMax) { }
        public RandomCondBlock(float aThreshold, float aMinValue, float aMaxValue)
        {
            min = aMinValue;
            max = aMaxValue;
            threshold = aThreshold;
        }
        #endregion

        #region Overrides
        public override string ToString()
        {
            if (min == 0)
            {
                if (max == 1)
                    return "(if (> rand " + threshold + ") ";
                else
                    return "(if (> (* rand " + max + ") " + threshold + ") ";
            }
            else
            {
                return "(if (> (+ " + min + " (* rand " + (max - min) + ")) " + threshold + ") ";
            }
        }
        #endregion

        #region Abstract overrides
        public override string BlockName
        {
            get { return "Rand Cond"; }
        }
        public override ParenType ParenType
        {
            get { return ParenType.NeedsItem; }
        }
        public override BlockType BlockType
        {
            get { return BlockType.Condition; }
        }
        public override string Description
        {
            get { return "If random " + min + "-" + max +" > "+ threshold; }
        }
        public override string IconName
        {
            get { return "If.png"; }
        }
        #endregion
    }
}
